package com.usian.mq;

import com.alibaba.fastjson.JSON;
import com.usian.mapper.XiansuoResultMapper;
import com.usian.model.pojos.XiansuoResult;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queuesToDeclare = @Queue(value = "loopMessage", durable = "true", autoDelete = "true"))
public class MessageConsummer {

    @Autowired
    private XiansuoResultMapper xiansuoResultMapper;

    @RabbitHandler
    public void getMessage(String message){
        System.out.println("mq接受到的消息："+message);

        XiansuoResult xiansuoResult = JSON.parseObject(message, XiansuoResult.class);
        xiansuoResultMapper.insert(xiansuoResult);

        System.out.println("mq 入库消息："+xiansuoResult.toString());



    }
}
